{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1176a3c6",
   "metadata": {},
   "source": [
    "\n",
    "-------\n",
    "* 日期：2022-09-07（week 03）\n",
    "* 课程：python\n",
    "* 记录人：洪梦瑶\n",
    "-------\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df1daca3",
   "metadata": {},
   "source": [
    "# 本周学习内容：\n",
    "{参考链接：https://www.cnblogs.com/xuzhichao/p/11407192.html｝\n",
    "\n",
    "> 1.变量\n",
    ">> 1.变量的定义与声明\n",
    "* 变量、赋值、数据三者是共同存在的\n",
    "eg：name=“hong mengyao”，变量名为“name”，变量name的值为“hong mengyao” \n",
    ">> 2.变量名的一般规则\n",
    "* 变量名只能是 字母、数字或下划线的任意组合\n",
    "* 变量名的第一个字符不能是数字\n",
    "* 以下关键字不能声明为变量名\n",
    "['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda','not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']\n",
    "\n",
    "> 2.编程的控制流\n",
    ">> 1.条件判断\n",
    "\n",
    ">> 2.循环遍历\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62cfd735",
   "metadata": {},
   "source": [
    "### 1.变量学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "b5070e29",
   "metadata": {},
   "outputs": [],
   "source": [
    "网一洪梦瑶_ID = \"00\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "87130388",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网一洪梦瑶_ID\n"
     ]
    }
   ],
   "source": [
    "print(\"网一洪梦瑶_ID\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6a999b65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'00'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网一洪梦瑶_ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "fa9b35f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "网一小白_ID = \"01\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ac16e05f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'01'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网一小白_ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3b85f63d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "00 00\n",
      "03 00\n"
     ]
    }
   ],
   "source": [
    "网一洪梦瑶_ID = \"00\"\n",
    "网一小白_ID = 网一洪梦瑶_ID\n",
    "print(网一洪梦瑶_ID,网一小白_ID)\n",
    "网一洪梦瑶_ID = \"03\"\n",
    "print(网一洪梦瑶_ID,网一小白_ID)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6b0a0e41",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'03'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网一洪梦瑶_ID"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6fe326e",
   "metadata": {},
   "source": [
    "### 2.条件判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "06bd6e7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课本案例P18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "88e348e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Recover,then rest.\n"
     ]
    }
   ],
   "source": [
    "# 变量today需要先赋值(一个等号是赋值，两个等号是判断)\n",
    "# 该部分码的时候出现的错误为第五行“elif”打错为else！！！以后需注意！！\n",
    "today = \"Sunday\"\n",
    "condition = \"Headache\"\n",
    "if today == \"Saturday\" :\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\" :\n",
    "    if condition == \"Headache\" :\n",
    "        print(\"Recover,then rest.\")\n",
    "    else :\n",
    "        print(\"Rest.\")\n",
    "else :\n",
    "    print(\"work,work,work\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "77793fd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#练习：判断今天是否有python课，判断python课是不是现在ing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "08a77f76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=7, tm_hour=20, tm_min=8, tm_sec=56, tm_wday=2, tm_yday=250, tm_isdst=0)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "4f2dcfe8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "20\n",
      "38\n",
      "今天有python课\n",
      "python课ing\n"
     ]
    }
   ],
   "source": [
    "# 创建week_day变量\n",
    "week_day = time.localtime().tm_wday\n",
    "print(week_day)\n",
    "\n",
    "time_hour = time.localtime().tm_hour\n",
    "print(time_hour)\n",
    "\n",
    "time_min = time.localtime().tm_min\n",
    "print(time_min)\n",
    "\n",
    "if week_day == 2 :\n",
    "    print(\"今天有python课\")\n",
    "    if time_hour == 19 :\n",
    "        print(\"python课ing\")\n",
    "    elif time_hour == 18 and time_min > 44 :\n",
    "        print(\"python课ing\")\n",
    "    elif time_hour == 20 and time_min < 51 :\n",
    "         print(\"python课ing\")\n",
    "    elif time_hour< 18 :\n",
    "        print(\"期待今天的课\")\n",
    "    else :\n",
    "        print(\"今天的课很不错\")\n",
    "else:\n",
    "    print(\"今天不是周三，没有python课\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "591f4a26",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(time）（去掉#然后运行可得到数值）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9029c8b2",
   "metadata": {},
   "source": [
    "### 3. 循环遍历\n",
    "* 1.for循环\n",
    "* 2.range()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "cd49951e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# 用例1\n",
    "# i是for循环里面的变量，第一次循环i是1，第二次循环i是2，第三次循环i是3\n",
    "for i in [1,2,3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "4de986e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "# 用例2\n",
    "# \"Hi!\"由 H、i、！组成\n",
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "2f230967",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# 用例3\n",
    "# range(5)表示将for循环控制在五次循环\n",
    "for num in range(5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "4b3c3d8e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# 用例3扩展1\n",
    "for num in range(1,5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "0ef01ab4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n",
      "5\n",
      "7\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# 用例3扩展2 起点为1，终点为10，步长为2\n",
    "for num in range(1,10,2):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "cc6d0490",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "8\n",
      "6\n",
      "4\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "# 用例3扩展3\n",
    "for num in range(10,1,-2):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b878ca9",
   "metadata": {},
   "source": [
    "# 课后作业：\n",
    "P35项目和P43项目"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
